package com.cn.scenario.util.mq.produder;

import com.alibaba.fastjson.JSON;
import com.cn.scenario.util.mq.pojo.StrsqlResData;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Boolean
 * @Date 2021/3/31 16:49
 * @Version 1.0
 */
@Service
public class ProduderService {
    /**
     * 生产者的组名
     */
    @Value("${rocketmq.producerGroup}")
    private  String producerGroup;

    /**
     * NameServer 地址
     */
    @Value("${rocketmq.namesrvaddr}")
    private  String namesrvAddr;

    public void produder_to(List<StrsqlResData> strsqlResDataList){
        /*DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
        producer.setNamesrvAddr(namesrvAddr);
        try {
            producer.start();
            for (int i = 0; i < strsqlResDataList.size(); i++) {
                    String jsonstr = JSON.toJSONString(strsqlResDataList.get(i));
                    System.out.println("发送消息:"+jsonstr);
                    Message message = new Message("check-topic", "check-tag", jsonstr.getBytes(RemotingHelper.DEFAULT_CHARSET));
                    SendResult result = producer.send(message);
                    System.err.println("发送响应：MsgId:" + result.getMsgId() + "，发送状态:" + result.getSendStatus());

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            producer.shutdown();
        }*/
    }
}
